<template>
	<view class="">
		<u-section v-if="showSection" class="section" title="基本信息" :right="false"></u-section>
		<u-cell-group>
			<u-cell-item
				v-show="selectedFields.includes(1) || displayAll"
				:arrow="false"
				:title="level != 3 ? addPrefix('经销商名称') : '门店名称'"
				:value="data.Dealer_BaseInfo.Name"
			></u-cell-item>
			<u-cell-item :arrow="false" :title="level != 3 ? addPrefix('经销商代码') : '门店代码'" :value="data.Dealer_BaseInfo.Account"></u-cell-item>
			<u-cell-item v-if="showParent" :arrow="false" title="上级" :value="data.Dealer_BaseInfo.Parent_Name"></u-cell-item>
			<u-cell-item v-if="showKeDealerNo" :arrow="false" :title="addPrefix('金蝶编码')" :value="data.Dealer_BaseInfo.KeDealerNo"></u-cell-item>
			<u-cell-item
				v-show="selectedFields.includes(2) || displayAll"
				:arrow="false"
				:title="level != 3 ? addPrefix('经销商简称') : '门店简称'"
				:value="data.Dealer_BaseInfo.Referred"
			></u-cell-item>
			<u-cell-item v-show="selectedFields.includes(3) || displayAll" :arrow="false" :title="addPrefix('负责人')" :value="data.Dealer_BaseInfo.NickName"></u-cell-item>
			<u-cell-item v-show="selectedFields.includes(4) || displayAll" :arrow="false" :title="addPrefix('手机号')" :value="data.Dealer_BaseInfo.Mobile"></u-cell-item>

			<block v-if="loadCity && (selectedFields.includes(5) || displayAll)">
				<u-cell-item :arrow="false" :title="addPrefix('公司地址')">
					<city-select :disabled="true" :value="areaCode"></city-select>
					<u-input :customStyle="customStyle" :disabled="true" inputAlign="right" :value="data.Dealer_BaseInfo.Address"></u-input>
				</u-cell-item>
				<u-cell-item v-if="showDeliveryAddress" :arrow="false" :title="addPrefix('收货地址')">
					<city-select :disabled="true" :value="deliveryAreaCode"></city-select>
					<u-input :customStyle="customStyle" :disabled="true" inputAlign="right" :value="data.Dealer_BaseInfo.Delivery_Address"></u-input>
				</u-cell-item>
				<u-cell-item :arrow="false">
					<view class="u-font-9 u-text-left">*务必详细确保能收到快递（不必在详细地址栏填写省、市、区，只需填写街道名称，门牌号码，楼层和房间号等信息）</view>
				</u-cell-item>
			</block>

			<block v-if="level == 3 && data.Dealer_OtherInfo">
				<u-cell-item title="门店位置" :arrow="false" v-if="selectedFields.includes(31) || displayAll">
					<!-- <u-input type="select" :value="location.label" placeholder="请选择" input-align="right" @click="showLocationPicker = true"></u-input> -->
					<view class="">{{ data.Dealer_OtherInfo && data.Dealer_OtherInfo.Store_Location }}</view>
					<view class="">{{ data.Dealer_OtherInfo && data.Dealer_OtherInfo.Store_Location_Other }}</view>
				</u-cell-item>
				<u-cell-item v-if="selectedFields.includes(32) || displayAll" title="门店BDR面积" :arrow="false" :value="data.Dealer_OtherInfo && data.Dealer_OtherInfo.BDR_Area"></u-cell-item>
				<u-cell-item v-if="selectedFields.includes(33) || displayAll" title="店内面积" :arrow="false" :value=" data.Dealer_OtherInfo && data.Dealer_OtherInfo.Store_Area"></u-cell-item>
				<u-cell-item v-if="selectedFields.includes(49) || displayAll" title="门店其他产品占用面积" :arrow="false" :value=" data.Dealer_OtherInfo && data.Dealer_OtherInfo.OtherProductArea"></u-cell-item>
			</block>

			<template v-if="showOtherInfo">
				<block v-if="level != 3">
					<block v-if="selectedFields.includes(6) || displayAll">
						<u-cell-item :border-bottom="false" :arrow="false" :title="addPrefix('证照')">
							<view class="u-flex u-row-right">
								<u-image @click="$preview(data.Dealer_OtherInfo.BusinessLicenseA)" :width="220" :height="170" :src="$getImageUrl(data.Dealer_OtherInfo.BusinessLicenseA)"></u-image>
							</view>
						</u-cell-item>
						<u-cell-item :arrow="false"><view class="u-font-9 u-text-left">上传营业执照扫描件/相片，无营业执照的须上传老板的身份证</view></u-cell-item>
					</block>

					<u-cell-item v-if="selectedFields.includes(7) || displayAll" :arrow="false" :title="addPrefix('经销协议')">
						<view class="u-flex u-row-right">
							<u-image v-if="data.Dealer_OtherInfo.TreatyPhotoType == 1" :width="220" :height="170" :src="$getImageUrl(data.Dealer_OtherInfo.TreatyPhoto)"></u-image>
							<text v-if="data.Dealer_OtherInfo.TreatyPhotoType == 4" @tap="toViewFile(data.Dealer_OtherInfo.TreatyPhoto)">点击查看</text>
						</view>
					</u-cell-item>
				</block>
				

				<block v-if="showSalesInfo">
					
					<u-cell-item v-if="selectedFields.includes(8) || displayAll" :arrow="false" :title="addPrefix('属性')">
						<u-radio-group :value="data.Dealer_OtherInfo.DealerType">
							<view class="grid-2">
								<u-radio :disabled="true" v-for="(item, index) in metadata.DealerType_BaseList" :key="index" :name="item.Key">{{ item.Value }}</u-radio>
							</view>
						</u-radio-group>
					</u-cell-item>
					<u-cell-item v-if="selectedFields.includes(9) || displayAll" :arrow="false" :title="addPrefix('经营品类')">
						<u-checkbox-group>
							<view class="grid-2">
								<u-checkbox :disabled="true" v-model="item.checked" v-for="(item, index) in metadata.BusinessCategory_BaseList" :name="item.Key" :key="index">
									{{ item.Value }}
								</u-checkbox>
							</view>
						</u-checkbox-group>
					</u-cell-item>
					<u-cell-item
						v-if="!displayAll && (selectedFields.includes(10) || selectedFields.includes(11) || selectedFields.includes(12))"
						:arrow="false"
						:title="addPrefix('竞品品牌')"
					>
						<block v-if="selectedFields.includes(10) || displayAll">
							<view class="u-text-left u-p-l-20">BDR品牌数: {{ count_A }}</view>
							<u-checkbox-group>
								<view class="grid-2">
									<u-checkbox :disabled="true" v-model="item.checked" v-for="(item, index) in metadata.CompetingGoodsBrandA_BaseList" :key="index" :name="item.Key">
										{{ item.Value }}
									</u-checkbox>
								</view>
							</u-checkbox-group>
							<u-line></u-line>
						</block>
					
						<block v-if="selectedFields.includes(11) || displayAll">
							<view class="u-text-left u-p-l-20">进口品牌数: {{ count_B }}</view>
							<u-checkbox-group>
								<view class="grid-2">
									<u-checkbox :disabled="true" v-model="item.checked" class="grid-item" v-for="(item, index) in metadata.CompetingGoodsBrandB_BaseList" :key="index" :name="item.Key">
										{{ item.Value }}
									</u-checkbox>
								</view>
							</u-checkbox-group>
							<u-line></u-line>
						</block>
					
						<block v-if="selectedFields.includes(12) || displayAll">
							<view class="u-text-left u-p-l-20">国产品牌数: {{ count_C }}</view>
							<u-checkbox-group>
								<view class="grid-2">
									<u-checkbox :disabled="true" v-model="item.checked" v-for="(item, index) in metadata.CompetingGoodsBrandC_BaseList" :key="index" :name="item.Key">
										{{ item.Value }}
									</u-checkbox>
								</view>
							</u-checkbox-group>
						</block>
					</u-cell-item>
					<u-cell-item v-if="(selectedFields.includes(13) || displayAll) && level != 3" :arrow="false" :title="addPrefix('上年BDR销售额')">
						<view class="u-flex-col u-col-bottom">
							<view>
								<text>{{ data.Dealer_OtherInfo.LastYearsBDRSales }}</text>
								<text class="unit u-m-l-32">万元</text>
							</view>
							<text class="desc">*BDR品牌的年销售额，新开的可预估</text>
						</view>
					</u-cell-item>

					<u-cell-item v-if="(selectedFields.includes(14) || displayAll) && level != 3" :arrow="false" :title="addPrefix('总销售额')">
						<view class="u-flex-col u-col-bottom">
							<view>
								<text>{{ data.Dealer_OtherInfo.TotalSales }}</text>
								<text class="unit u-m-l-32">万元</text>
							</view>
							<text class="desc">*所有品类的年销售额</text>
						</view>
					</u-cell-item>
					<!-- <u-cell-item :arrow="false" :title="addPrefix('BDR销售额占比')">
					<view class="u-flex-col u-col-bottom">
						<view>
							<text>{{ data.Dealer_OtherInfo.PercentageBDRSales }}</text>
							<text class="unit">%</text>
						</view>
						<text class="desc">*上年BDR销售额/总销售额</text>
					</view>
				</u-cell-item> -->

					<u-cell-item v-if="selectedFields.includes(34) || displayAll" :arrow="false" title="上一年对应代理商供暖销售额">
						<view class="u-flex-col u-col-bottom">
							<view class="u-flex">
								<u-input disabled v-model="data.Dealer_OtherInfo.LY_DealerHeatingSales" type="number" inputAlign="right" placeholder="请输入"></u-input>
								<text class="unit u-m-l-32">万元</text>
							</view>
						</view>
					</u-cell-item>

					<u-cell-item v-if="selectedFields.includes(35) || displayAll" :arrow="false" title="上一年对应代理商空凋销售额">
						<view class="u-flex-col u-col-bottom">
							<view class="u-flex">
								<u-input disabled v-model="data.Dealer_OtherInfo.LY_DealerAirConditionerSales" type="number" inputAlign="right" placeholder="请输入"></u-input>
								<text class="unit u-m-l-32">万元</text>
							</view>
						</view>
					</u-cell-item>

					<u-cell-item v-if="selectedFields.includes(36) || displayAll" :arrow="false" title="上一年对应代理商净水销售额">
						<view class="u-flex-col u-col-bottom">
							<view class="u-flex">
								<u-input disabled v-model="data.Dealer_OtherInfo.LY_DealerPurifiedWaterSales" type="number" inputAlign="right" placeholder="请输入"></u-input>
								<text class="unit u-m-l-32">万元</text>
							</view>
						</view>
					</u-cell-item>

					<u-cell-item v-if="selectedFields.includes(50) || displayAll" :arrow="false" title="上一年门店供暖销售额">
						<view class="u-flex-col u-col-bottom">
							<view class="u-flex">
								<u-input disabled v-model="data.Dealer_OtherInfo.LY_StoreHeatingSales" type="number" inputAlign="right" placeholder="请输入"></u-input>
								<text class="unit u-m-l-32">万元</text>
							</view>
						</view>
					</u-cell-item>

					<u-cell-item v-if="selectedFields.includes(51) || displayAll" :arrow="false" title="上一年门店空凋销售额">
						<view class="u-flex-col u-col-bottom">
							<view class="u-flex">
								<u-input disabled v-model="data.Dealer_OtherInfo.LY_StoreAirConditionerSales" type="number" inputAlign="right" placeholder="请输入"></u-input>
								<text class="unit u-m-l-32">万元</text>
							</view>
						</view>
					</u-cell-item>

					<u-cell-item v-if="selectedFields.includes(52) || displayAll" :arrow="false" title="上一年门店净水销售额">
						<view class="u-flex-col u-col-bottom">
							<view class="u-flex">
								<u-input disabled v-model="data.Dealer_OtherInfo.LY_Store_BDR_PurifiedWaterSales" type="number" inputAlign="right" placeholder="请输入"></u-input>
								<text class="unit u-m-l-32">万元</text>
							</view>
						</view>
					</u-cell-item>

					<u-cell-item v-if="selectedFields.includes(53) || displayAll" :arrow="false" title="上一年销售BDR供暖产品台数">
						<view class="u-flex-col u-col-bottom">
							<view class="u-flex">
								<u-input disabled v-model="data.Dealer_OtherInfo.LY_Store_BDR_HeatingSalesNum" type="number" inputAlign="right" placeholder="请输入"></u-input>
								<text class="unit u-m-l-32">台</text>
							</view>
						</view>
					</u-cell-item>

					<u-cell-item v-if="selectedFields.includes(54) || displayAll" :arrow="false" title="上一年销售BDR净水产品台数">
						<view class="u-flex-col u-col-bottom">
							<view class="u-flex">
								<u-input disabled v-model="data.Dealer_OtherInfo.LY_Store_BDR_AirConditionerSalesNum" type="number" inputAlign="right" placeholder="请输入"></u-input>
								<text class="unit u-m-l-32">台</text>
							</view>
						</view>
					</u-cell-item>

					<u-cell-item v-if="selectedFields.includes(55) || displayAll" :arrow="false" title="上一年销售BDR热泵产品台数">
						<view class="u-flex-col u-col-bottom">
							<view class="u-flex">
								<u-input disabled v-model="data.Dealer_OtherInfo.LY_Store_BDR_PurifiedWaterSalesNum" type="number" inputAlign="right" placeholder="请输入"></u-input>
								<text class="unit u-m-l-32">台</text>
							</view>
						</view>
					</u-cell-item>
				</block>

				<u-cell-item :arrow="false" title="人员数量" v-if="level != 3">
					<view class="u-flex-col u-col-bottom">
						<view>
							<text>{{ data.Dealer_OtherInfo.PeopleNum }}</text>
							<text class="unit"></text>
						</view>
						<text class="desc">*不含售后安装人员</text>
					</view>
				</u-cell-item>
				<u-cell-item :border-bottom="false" v-if="showGrade" :arrow="false" :title="addPrefix('等级')">
					<u-radio-group :value="data.Dealer_OtherInfo.DealerGrade">
						<view class="grid-3">
							<u-radio v-model="item.checked" :disabled="true" v-for="(item, index) in metadata.DealerGrade_BaseList" :key="index" :name="item.Key">{{ item.Value }}</u-radio>
						</view>
					</u-radio-group>
				</u-cell-item>
			</template>
		</u-cell-group>

		<template v-if="showReview">
			<u-section v-if="showSection" class="section" title="审核信息" :right="false"></u-section>
			<u-cell-group :border="false">
				<u-cell-item title="审核状态" :arrow="false" :value="data.DealerDetail_Audit.AuditStateName"></u-cell-item>
				<review-flow :data="data.AuditForList"></review-flow>
				<u-cell-item title="申请时间" :arrow="false">{{ (data.DealerDetail_Audit.ApplayTime * 1000) | date('yyyy-mm-dd') }}</u-cell-item>
				<u-cell-item title="申请备注" :arrow="false">
					<u-input type="textarea" inputAlign="right" placeholder="" :value="data.DealerDetail_Audit.ApplayRemark" :disabled="true"></u-input>
				</u-cell-item>
			</u-cell-group>
		</template>
	</view>
</template>

<script>
export default {
	props: {
		level: {
			type: [Number, String],
			default: 1
		},
		showSection: {
			type: Boolean,
			default: false
		},
		showOtherInfo: {
			type: Boolean,
			default: true
		},
		showReview: {
			type: Boolean,
			default: true
		},
		showDeliveryAddress: {
			type: Boolean,
			default: true
		},
		showParent: {
			type: Boolean,
			default: true
		},
		showGrade: {
			type: Boolean,
			default: true
		},
		showKeDealerNo: {
			type: Boolean,
			default: false
		},
		loadCity: {
			type: Boolean,
			default: true
		},
		selectedFields: {
			type: Array,
			default() {
				return [];
			}
		},
		displayAll: {
			type: Boolean,
			default: true
		},
		showSalesInfo: {
			type: Boolean,
			default: false
		},
		metadata: {
			type: Object,
			default() {
				return {
					BusinessCategory_BaseList: [],
					CompetingGoodsBrandA_BaseList: [],
					CompetingGoodsBrandB_BaseList: [],
					CompetingGoodsBrandC_BaseList: [],
					DealerApplyFor_BaseList: [],
					DealerGrade_BaseList: [],
					DealerMaterialRequirements_BaseList: [],
					DealerShutDown_BaseList: [],
					DealerType_BaseList: [],
					DealerAndGoReason_BaseList: []
				};
			}
		},
		data: {
			type: Object,
			default() {
				return {
					Dealer_BaseInfo: {
						Account: '',
						Address: '',
						CityId: 610100,
						Created: 1460613600,
						DealerId: 114,
						Delivery_Address: '',
						Delivery_CityId: 610100,
						Delivery_DistrictId: 659020,
						Delivery_ProvinceId: 610000,
						DistrictId: 659020,
						IsFictitious: 0,
						KeDealerNo: '01000090',
						Level: 1,
						LevelName: '',
						Mobile: '',
						Name: '',
						NickName: '',
						Parent_DealerId: 90,
						Parent_Name: '',
						ProvinceId: 610000,
						Referred: '',
						State: 4,
						Telephone: ''
					},
					Dealer_OtherInfo: {
						BlessingNote: '',
						BossBirthday: 1626192000,
						BossName: '',
						BossPhone: '',
						BusinessCategory: '',
						BusinessLicenseA: '',
						CompetingGoodsBrandA: '',
						CompetingGoodsBrandB: '',
						CompetingGoodsBrandC: '',
						DealerGrade: 1,
						DealerType: 1,
						IsSign: 2,
						IsVIP: 1,
						LastYearsBDRSales: 14001,
						PeopleNum: 25,
						PercentageBDRSales: 35,
						TotalSales: 40001,
						TreatyPhoto: 'o_1ed682sou1iuf2lmc37rc31jjjd.png',
						TreatyPhotoType: 1
					},
					DealerDetail_Audit: {
						ApplayRemark: '',
						ApplayTime: 1628611200,
						AuditState: 1,
						AuditStateName: '待初审',
						// 终审
						FinalAuditNote: '',
						// 初审
						FirstAuditNote: '',
						// 复审
						ReviewAuditNote: ''
					},
					AuditForList: []
				};
			}
		}
	},
	data() {
		return {
			customStyle: {
				color: '#909399',
				fontSize: '26rpx'
			}
		};
	},

	methods: {
		addPrefix(text) {
			let prefix = '';
			if (this.level == 1) {
				prefix = '一级';
			}
			if (this.level == 2) {
				prefix = '二级';
			}
			return prefix + text;
		},
		toViewFile(file) {
			window.location.href = this.$getImageUrl(file);
		}
	},

	computed: {
		count_A() {
			if (!this.metadata.CompetingGoodsBrandA_BaseList) {
				return 0;
			}
			return this.metadata.CompetingGoodsBrandA_BaseList.filter(item => item.checked).length;
		},
		count_B() {
			if (!this.metadata.CompetingGoodsBrandB_BaseList) {
				return 0;
			}
			return this.metadata.CompetingGoodsBrandB_BaseList.filter(item => item.checked).length;
		},
		count_C() {
			if (!this.metadata.CompetingGoodsBrandC_BaseList) {
				return 0;
			}
			return this.metadata.CompetingGoodsBrandC_BaseList.filter(item => item.checked).length;
		},
		areaCode() {
			return [this.data.Dealer_BaseInfo.ProvinceId, this.data.Dealer_BaseInfo.CityId, this.data.Dealer_BaseInfo.DistrictId];
		},
		deliveryAreaCode() {
			return [this.data.Dealer_BaseInfo.Delivery_ProvinceId, this.data.Dealer_BaseInfo.Delivery_CityId, this.data.Dealer_BaseInfo.Delivery_DistrictId];
		}
	}
};
</script>

<style lang="scss" scoped></style>
